﻿using System;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbPropertiesOverrule : OdRxOverrule
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbPropertiesOverrule(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbPropertiesOverrule_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbPropertiesOverrule obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbPropertiesOverrule()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbPropertiesOverrule(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public OdDbPropertiesOverrule() : this(TD_DbPINVOKE.new_OdDbPropertiesOverrule(), MemoryManager.GetMemoryManager().GetCurrentTransaction() == null)
		{
			MemoryTransaction currentTransaction = MemoryManager.GetMemoryManager().GetCurrentTransaction();
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbPropertiesOverrule(this.swigCPtr.Handle, true));
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			this.SwigDirectorConnect();
		}

		public new static OdDbPropertiesOverrule cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbPropertiesOverrule_cast(OdRxObject.getCPtr(pObj));
			OdDbPropertiesOverrule result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbPropertiesOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbPropertiesOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbPropertiesOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbPropertiesOverrule_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(this.SwigDerivedClassHasMethod("isA", OdDbPropertiesOverrule.swigMethodTypes1) ? TD_DbPINVOKE.OdDbPropertiesOverrule_isASwigExplicitOdDbPropertiesOverrule(this.swigCPtr) : TD_DbPINVOKE.OdDbPropertiesOverrule_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(this.SwigDerivedClassHasMethod("queryX", OdDbPropertiesOverrule.swigMethodTypes0) ? TD_DbPINVOKE.OdDbPropertiesOverrule_queryXSwigExplicitOdDbPropertiesOverrule(this.swigCPtr, OdRxClass.getCPtr(protocolClass)) : TD_DbPINVOKE.OdDbPropertiesOverrule_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdDbPropertiesOverrule createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbPropertiesOverrule_createObject();
			OdDbPropertiesOverrule result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbPropertiesOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbPropertiesOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbPropertiesOverrule)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult getClassID(OdDbObject pSubject, IntPtr pClsid)
		{
			OdResult result = (OdResult)(this.SwigDerivedClassHasMethod("getClassID", OdDbPropertiesOverrule.swigMethodTypes3) ? TD_DbPINVOKE.OdDbPropertiesOverrule_getClassIDSwigExplicitOdDbPropertiesOverrule(this.swigCPtr, OdDbObject.getCPtr(pSubject), pClsid) : TD_DbPINVOKE.OdDbPropertiesOverrule_getClassID(this.swigCPtr, OdDbObject.getCPtr(pSubject), pClsid));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void list(OdDbEntity pSubject)
		{
			if (this.SwigDerivedClassHasMethod("list", OdDbPropertiesOverrule.swigMethodTypes4))
			{
				TD_DbPINVOKE.OdDbPropertiesOverrule_listSwigExplicitOdDbPropertiesOverrule(this.swigCPtr, OdDbEntity.getCPtr(pSubject));
			}
			else
			{
				TD_DbPINVOKE.OdDbPropertiesOverrule_list(this.swigCPtr, OdDbEntity.getCPtr(pSubject));
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		private void SwigDirectorConnect()
		{
			if (this.SwigDerivedClassHasMethod("queryX", OdDbPropertiesOverrule.swigMethodTypes0))
			{
				this.swigDelegate0 = new OdDbPropertiesOverrule.SwigDelegateOdDbPropertiesOverrule_0(this.SwigDirectorqueryX);
			}
			if (this.SwigDerivedClassHasMethod("isA", OdDbPropertiesOverrule.swigMethodTypes1))
			{
				this.swigDelegate1 = new OdDbPropertiesOverrule.SwigDelegateOdDbPropertiesOverrule_1(this.SwigDirectorisA);
			}
			if (this.SwigDerivedClassHasMethod("isApplicable", OdDbPropertiesOverrule.swigMethodTypes2))
			{
				this.swigDelegate2 = new OdDbPropertiesOverrule.SwigDelegateOdDbPropertiesOverrule_2(this.SwigDirectorisApplicable);
			}
			if (this.SwigDerivedClassHasMethod("getClassID", OdDbPropertiesOverrule.swigMethodTypes3))
			{
				this.swigDelegate3 = new OdDbPropertiesOverrule.SwigDelegateOdDbPropertiesOverrule_3(this.SwigDirectorgetClassID);
			}
			if (this.SwigDerivedClassHasMethod("list", OdDbPropertiesOverrule.swigMethodTypes4))
			{
				this.swigDelegate4 = new OdDbPropertiesOverrule.SwigDelegateOdDbPropertiesOverrule_4(this.SwigDirectorlist);
			}
			TD_DbPINVOKE.OdDbPropertiesOverrule_director_connect(this.swigCPtr, this.swigDelegate0, this.swigDelegate1, this.swigDelegate2, this.swigDelegate3, this.swigDelegate4);
		}

		private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes)
		{
			MethodInfo method = base.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, methodTypes, null);
			return method.DeclaringType.IsSubclassOf(typeof(OdDbPropertiesOverrule));
		}

		private IntPtr SwigDirectorqueryX(IntPtr protocolClass)
		{
			return OdRxObject.getCPtr(this.queryX((OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(protocolClass, false))).Handle;
		}

		private IntPtr SwigDirectorisA()
		{
			return OdRxClass.getCPtr(this.isA()).Handle;
		}

		private bool SwigDirectorisApplicable(IntPtr pOverruledSubject)
		{
			return this.isApplicable(Teigha.Core.Helpers.odrxCreateObjectInternal(pOverruledSubject, false));
		}

		private int SwigDirectorgetClassID(IntPtr pSubject, IntPtr pClsid)
		{
			return (int)this.getClassID((OdDbObject)Teigha.Core.Helpers.odrxCreateObjectInternal(pSubject, false), pClsid);
		}

		private void SwigDirectorlist(IntPtr pSubject)
		{
			this.list((OdDbEntity)Teigha.Core.Helpers.odrxCreateObjectInternal(pSubject, false));
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		private OdDbPropertiesOverrule.SwigDelegateOdDbPropertiesOverrule_0 swigDelegate0;

		private OdDbPropertiesOverrule.SwigDelegateOdDbPropertiesOverrule_1 swigDelegate1;

		private OdDbPropertiesOverrule.SwigDelegateOdDbPropertiesOverrule_2 swigDelegate2;

		private OdDbPropertiesOverrule.SwigDelegateOdDbPropertiesOverrule_3 swigDelegate3;

		private OdDbPropertiesOverrule.SwigDelegateOdDbPropertiesOverrule_4 swigDelegate4;

		private static Type[] swigMethodTypes0 = new Type[]
		{
			typeof(OdRxClass)
		};

		private static Type[] swigMethodTypes1 = new Type[0];

		private static Type[] swigMethodTypes2 = new Type[]
		{
			typeof(OdRxObject)
		};

		private static Type[] swigMethodTypes3 = new Type[]
		{
			typeof(OdDbObject),
			typeof(IntPtr)
		};

		private static Type[] swigMethodTypes4 = new Type[]
		{
			typeof(OdDbEntity)
		};

		public delegate IntPtr SwigDelegateOdDbPropertiesOverrule_0(IntPtr protocolClass);

		public delegate IntPtr SwigDelegateOdDbPropertiesOverrule_1();

		public delegate bool SwigDelegateOdDbPropertiesOverrule_2(IntPtr pOverruledSubject);

		public delegate int SwigDelegateOdDbPropertiesOverrule_3(IntPtr pSubject, IntPtr pClsid);

		public delegate void SwigDelegateOdDbPropertiesOverrule_4(IntPtr pSubject);
	}
}
